package lixp.jwt.controller;

import lixp.res.Result;
import lixp.res.ResultUtil;
import lixp.jwt.config.JwtToken;
import lixp.jwt.utils.Imp.JwtUtilForJJwt;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
public class JwtController {

    org.slf4j.Logger logger = LoggerFactory.getLogger(JwtController.class);

    @Autowired
    JwtUtilForJJwt jwtUtilForJJwt;
    /**
     * 登录并获取token
     * @param username
     * @param password
     * @return
     */
    @PostMapping("/login")
    public Result login(String username, String password)  {
        logger.info(username);
        Integer userId = 5;
        // 生成签名
        String token= jwtUtilForJJwt.creatToken(userId);
        HashMap<String, String> map = new HashMap<>();
        map.put("token",token);
        logger.info(token);
        return ResultUtil.success(map);
    }

    /**
     * 该接口需要带签名才能访问
     * @return
     */
    @JwtToken
    @GetMapping("/getMessage")
    public Result getMessage(){

        return ResultUtil.success();
    }
}
